<?php
require_once '../mvc/anuncio_view.php';

class AnuncioController{
	private $anuncio_view;

	function __construct(){
	        $this->anuncio_view = new AnuncioView();
	}

	function get_nick( $id ){
		$query = "SELECT Op_nick FROM Operacion WHERE Op_id = $id";
		$result = $GLOBALS['mysql_connection']->query( $query);
		
		$row = $result->fetch_array();
		return $row['Op_nick'];
	}

	function GetAnuncios(){
		$query = "SELECT Anun_Rem, Anun_Post FROM Anuncios ORDER BY Anun_Id DESC";
		$result = $GLOBALS['mysql_connection']->query( $query);

		$Shouts = '';
		while ($row = $result->fetch_array()){
			$remitente = $row['Anun_Rem'];
			$post = $row['Anun_Post'];
			$Shouts .= '<li>' .$this->get_nick($remitente). ':  ' .$post. '</li>';
		}
		return $Shouts;
	}

	function display(){
		return $this->anuncio_view->display( $this->GetAnuncios() );
	}

	function NewAnuncio( $rem, $msg ){
		$sql = "INSERT INTO Shoutbox SET Anun_Rem = '$rem', Anun_Post = '$msg'"; 
		$result = $GLOBALS['mysql_connection']->query( $query);
	}
}

?>
